import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:imperius_insights/modules/projects/viewmodels/colors.dart';
import 'package:imperius_insights/modules/projects/viewmodels/project.dart';
import 'package:imperius_insights/modules/projects/viewmodels/strings.dart';
import 'package:imperius_insights/portal/widgets/responsive-widget.dart';
import 'package:imperius_insights/treaty/palette.dart';
import 'package:imperius_insights/treaty/styles.dart';

class MarkedProjects extends StatelessWidget {
  final List<ProjectViewModel> markedProjects;
  final DateTime day;
  final void Function(ProjectViewModel project) onProjectTap;

  MarkedProjects(this.markedProjects, this.day, this.onProjectTap);

  @override
  Widget build(BuildContext context) {
    if (markedProjects == null) {
      return Container();
    }
    final listWidget = ListView.separated(
      shrinkWrap: true,
      separatorBuilder: (_, __) =>
          Divider(color: palette.divider, thickness: 1, height: 0),
      itemBuilder: (BuildContext context, int index) {
        final project = markedProjects[index];
        final stagingLater = project.calcMilestoneStaging(day);
        return InkWell(
          onTap: () => onProjectTap(project),
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 6, vertical: 6),
            child: Row(children: <Widget>[
              ConstrainedBox(
                constraints: BoxConstraints(minWidth: 45),
                child: Container(
                  margin: EdgeInsets.only(right: 3),
                  padding: EdgeInsets.all(2),
                  decoration: BoxDecoration(
                      color: stagingToColor(stagingLater),
                      borderRadius: BorderRadius.circular(3)),
                  child: Center(
                    child: Text(stagingToTaskActionText(stagingLater),
                        style: styles.contentTipContrast),
                  ),
                ),
              ),
              Expanded(
                  child: Text(project.name,
                      maxLines: 1, overflow: TextOverflow.ellipsis))
            ]),
          ),
        );
      },
      itemCount: markedProjects.length,
    );
    return Expanded(
      child: Container(
        margin: EdgeInsets.all(6),
        decoration: BoxDecoration(
            border: Border.all(color: palette.divider),
            borderRadius: BorderRadius.circular(3)),
        child: Scrollbar(
          child: ResponsiveWidget.isLandscape(context) ? ConstrainedBox(
            constraints: BoxConstraints(maxWidth: 288),
            child: listWidget,
          ) : listWidget,
        ),
      ),
    );
  }
}
